package com.second.app.controller;

import com.second.app.common.SecondResponse;
import com.second.app.enums.CommonCodeEnum;
import com.second.app.util.JwtUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author gyz
 * @date 2020/12/26 10:23
 */
@RestController
@RequestMapping("second")
public class LoginController {


    @GetMapping("login")
    public SecondResponse login(@RequestParam("userNo") String userNo, @RequestParam("password") String password) {
        if (userNo.equals("admin") && password.equals("admin")) {
            String jwtToken = JwtUtils.generateToken(userNo);
            return new SecondResponse(CommonCodeEnum.OK.getCode(), "登录成功", jwtToken);
        }
        return new SecondResponse(CommonCodeEnum.ERROR.getCode(), "登录失败", "你没有权限登录此设备");
    }
}
